#ifndef THINK_THINK_RESPONSE_REDIRECT_H
#define THINK_THINK_RESPONSE_REDIRECT_H

static char* think_response_redirect =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think\\response;\n"
	"\n"
	"use think\\Request;\n"
	"use think\\Response;\n"
	"use think\\Session;\n"
	"use think\\Url;\n"
	"\n"
	"class Redirect extends Response\n"
	"{\n"
	"\n"
	"    protected $options = [];\n"
	"\n"
	"    // URL参数\n"
	"    protected $params = [];\n"
	"\n"
	"    public function __construct($data = \'\', $code = 302, array $header = [], array $options = [])\n"
	"    {\n"
	"        parent::__construct($data, $code, $header, $options);\n"
	"        $this->cacheControl(\'no-cache,must-revalidate\');\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 处理数据\n"
	"     * @access protected\n"
	"     * @param mixed $data 要处理的数据\n"
	"     * @return mixed\n"
	"     */\n"
	"    protected function output($data)\n"
	"    {\n"
	"        $this->header[\'Location\'] = $this->getTargetUrl();\n"
	"        return;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 重定向传值（通过Session）\n"
	"     * @access protected\n"
	"     * @param string|array  $name 变量名或者数组\n"
	"     * @param mixed         $value 值\n"
	"     * @return $this\n"
	"     */\n"
	"    public function with($name, $value = null)\n"
	"    {\n"
	"        if (is_array($name)) {\n"
	"            foreach ($name as $key => $val) {\n"
	"                Session::flash($key, $val);\n"
	"            }\n"
	"        } else {\n"
	"            Session::flash($name, $value);\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取跳转地址\n"
	"     * @return string\n"
	"     */\n"
	"    public function getTargetUrl()\n"
	"    {\n"
	"        if (strpos($this->data, \'://\') || (0 === strpos($this->data, \'/\') && empty($this->params))) {\n"
	"            return $this->data;\n"
	"        } else {\n"
	"            return Url::build($this->data, $this->params);\n"
	"        }\n"
	"    }\n"
	"\n"
	"    public function params($params = [])\n"
	"    {\n"
	"        $this->params = $params;\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 记住当前url后跳转\n"
	"     * @return $this\n"
	"     */\n"
	"    public function remember()\n"
	"    {\n"
	"        Session::set(\'redirect_url\', Request::instance()->url());\n"
	"        return $this;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 跳转到上次记住的url\n"
	"     * @return $this\n"
	"     */\n"
	"    public function restore()\n"
	"    {\n"
	"        if (Session::has(\'redirect_url\')) {\n"
	"            $this->data = Session::get(\'redirect_url\');\n"
	"            Session::delete(\'redirect_url\');\n"
	"        }\n"
	"        return $this;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif